﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AdvancedSearch.aspx.cs"
    Inherits="JKF.Web.Customer.AdvancedSearch" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <%= RegScript("~/js/jquery.1.5.js")%>
    <%=RegScript("~/js/Common.js")%>
    <%=RegScript("~/js/jquery.json.js")%>
    <%=RegScript("~/js/jquery.nhis.js")%>
    <%=RegScript("~/js/jquery.rchis.js")%>
    <%=RegScript("~/js/jquery.validate.js")%>
    <%=RegScript("~/js/DatePicker/WdatePicker.js")%>
    <%=RegStyle("~/js/suggest/jquery.suggest.css")%>
    <%=this.RegStyle("~/App_Themes/Theme2/Include.css")%>
    <style type="text/css">
        body { height: auto; }
        #LEVEL_CODE label, #GROUP_KEY label { margin-right: 8px; }
    </style>
    <script type="text/javascript">
        var appPath = "<%=AppPath %>";
        var areaHandler = appPath + '/do/Dic/Dic_Area.do';
        var curstomerHandler = appPath + '/do/Customer/Customer.do';
        var dtReg = /^\d{4}(\/|-)([1][0-2]|[1-9]|0[1-9])(\/|-)([1-2][0-9]|3[0-1]|[1-9]|0[1-9])( (0?[0-9]|1[0-9]|2[0-4])(:([0-5][0-9])){1,2})?$/;
        var tmpl = new DTemplate();
        $(function () {
            BindEvent();
        });
        function BindEvent() {
            $("#btnSearch").click(Search);
            $("#province").change(function () {
                $("#city").val("");
                $("#AREA_CODE").val("");
                $("#city").attr("disabled", "disabled");
                $("#AREA_CODE").attr("disabled", "disabled");
                if ($(this).val().length > 0) {
                    $.post(areaHandler, { ActionName: "GetAreaJson", code: $(this).val() }, function (obj) {
                        if (obj.Success) {
                            $("#city").empty();
                            $("#city").html("<option value=''>请选择</option>" + tmpl("<option value=\"${value}\">${text}</option>", obj.Data, true)).removeAttr("disabled");
                            if ($("#city").attr("pvl")) {
                                $("#city").val($("#city").attr("pvl")).change();
                            }
                        }
                    }, "json");
                }
            });
            $("#city").change(function () {
                $("#AREA_CODE").val("");
                $("#AREA_CODE").attr("disabled", "disabled");
                if ($(this).val().length > 0) {
                    $.post(areaHandler, { ActionName: "GetAreaJson", code: $(this).val() }, function (obj) {
                        if (obj.Success) {
                            $("#AREA_CODE").empty();
                            $("#AREA_CODE").html("<option value=''>请选择</option>" + tmpl("<option value=\"${value}\">${text}</option>", obj.Data, true)).removeAttr("disabled");
                            if ($("#AREA_CODE").attr("pvl")) $("#AREA_CODE").val($("#AREA_CODE").attr("pvl"));
                        }
                    }, "json");
                }
            });
            bingValid();
        }
        function Search() {
            if (!$.validateAll()) {
                if ($(".alxv-failed").size() > 0) {
                    $(document).scrollTop($(".alxv-failed").eq(0).scrollTop());
                }
                return;
            };
            var schObj = {
                CARD_NO: $.trim($("#CARD_NO").val()),
                LEVEL_CODE: "",
                NAME: $.trim($("#NAME").val()),
                SEX: $.trim($("#SEX").val()),
                REFEREE_CARD: $.trim($("#REFEREE_CARD").val()),
                REFEREE: $.trim($("#REFEREE").val()),
                ID_CARD: $.trim($("#ID_CARD").val()),
                AGEFROM: $.trim($.FxNull($("#AGEFROM").val(), "")),
                AGETO: $.trim($.FxNull($("#AGETO").val(), "")),
                MOBILE: $.trim($("#MOBILE").val()),
                PHONE: $.trim($("#PHONE").val()),
                AREA_CODE: $.trim($("#AREA_CODE").val()),
                DATE_CREATESTART: $.trim($("#DATE_CREATESTART").val()),
                DATE_CREATEEND: $.FxNull($.trim($("#DATE_CREATEEND").val()), ""),
                AVAPOINTFROM: $.trim($("#AVAPOINTFROM").val()),
                AVAPOINTTO: $.trim($("#AVAPOINTTO").val()),
                BIRTHDAYFROM: $.trim($("#BIRTHDAYFROM").val()),
                BIRTHDAYTO: $.trim($("#BIRTHDAYTO").val()),
                GROUP_KEY: "",
                LEVEL_NAME: "",
                GROUP_NAME: "",
                CITY: $.trim($("#city").val()),
                PROVINCE: $.trim($("#province").val()),
                CITY_NAME: "",
                PROVINCE_NAME: "",
                AREA_NAME: ""
            };
            var lvlSel = [], nms = [];
            $("#LEVEL_CODE").find(":checked").each(function () {
                lvlSel.push($(this).val());
                nms.push($.FxNull($(this).attr("nm"), ""));
            });
            schObj.LEVEL_CODE = lvlSel.join(",");
            schObj.LEVEL_NAME = nms.join(",");
            schObj.TITLE = $.trim($("#TITLE").val());
            schObj.FAMILY = $.trim($("#FAMILY").val());
            lvlSel = [];
            nms = [];
            $("#GROUP_KEY").find(":checked").each(function () { lvlSel.push($(this).val()); nms.push($.FxNull($(this).attr("nm"), "")); });
            schObj.GROUP_KEY = lvlSel.join(",");
            schObj.GROUP_NAME = nms.join(",");

            if ($.FxNull(schObj.PROVINCE, "").length > 0) {
                var nm = $("#province").find("option[value='" + schObj.PROVINCE + "']");
                if (nm.size() > 0) schObj.PROVINCE_NAME = nm.text();
            }
            if ($.FxNull(schObj.CITY, "").length > 0) {
                nm = $("#city").find("option[value='" + schObj.CITY + "']");
                if (nm.size() > 0) schObj.CITY_NAME = nm.text();
            }
            if ($.FxNull(schObj.AREA_CODE, "").length > 0) {
                nm = $("#AREA_CODE").find("option[value='" + schObj.AREA_CODE + "']");
                if (nm.size() > 0) schObj.AREA_NAME = nm.text();
            }

            parent.advSearch = schObj;
            top.popRetuInfo(schObj);
            top.tipsWindown.close();
        }

        function bingValid() {
            alxVr.push({
                id: "AGEFROM",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl != "") {
                        if (!/^(1)?\d{1,2}$/.test(vl)) {
                            this.msg = "年龄最小值格式不正确,应为数字且在199之内.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "AGETO",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl != "") {
                        if (!/^(1)?\d{1,2}$/.test(vl)) {
                            this.msg = "年龄最大值格式不正确,应为数字且在199之内.";
                            return false;
                        }
                        var min = $.trim($("#AGEFROM").val());
                        if (/^\d+$/.test(min) && (min - 0) > (vl - 0)) {
                            this.msg = "年龄最大值应大于等于年龄最小值.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "MOBILE",
                rule: function (cn) {
                    var actVal = $.trim(cn.val());
                    if (actVal == "") {
                        return true;
                    } else if (!/^(\+\d{1,})?1\d{8,}$/.test(actVal)) {
                        this.msg = "手机号格式不正确.";
                        return false;
                    }
                    //check exists
                    return true;
                }
            });
            alxVr.push({
                id: "TITLE",
                rule: function (cn) {
                    var actVal = $.trim(cn.val());
                    if (actVal == "") {
                        return true;
                    } else if (actVal.length > 50) {
                        this.msg = "职业应在50个字符之内.";
                        return false;
                    }
                    //check exists
                    return true;
                }
            });
            alxVr.push({
                id: "FAMILY",
                rule: function (cn) {
                    var actVal = $.trim(cn.val());
                    if (actVal == "") {
                        return true;
                    } else if (actVal.length > 500) {
                        this.msg = "家庭情况应在500个字符之内.";
                        return false;
                    }
                    //check exists
                    return true;
                }
            });
            alxVr.push({
                id: "PHONE",
                rule: function (cn) {
                    var actVal = $.trim(cn.val());
                    if (actVal.length > 0 && !/^[0-9()-]{20,}$/.test(actVal)) {
                        this.msg = "固定电话号码格式不正确.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "DATE_CREATESTART",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl != "") {
                        if (!dtReg.test(vl)) {
                            this.msg = "注册日期最小值不正确，应为日期（如:2012-1-1）.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "DATE_CREATEEND",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl != "") {
                        if (!dtReg.test(vl)) {
                            this.msg = "注册日期最大值不正确，应为日期（如:2012-1-1）.";
                            return false;
                        }
                        var min = $.trim($("#DATE_CREATESTART").val());
                        if (dtReg.test(min) && !dateCompare(min, vl)) {
                            this.msg = "注册日期最大值应大于等于注册日期最小值.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "BIRTHDAYFROM",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl != "") {
                        if (!dtReg.test(vl)) {
                            this.msg = "生日最小值不正确，应为日期（如:2012-1-1）.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "BIRTHDAYTO",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl != "") {
                        if (!dtReg.test(vl)) {
                            this.msg = "生日最大值不正确，应为日期（如:2012-1-1）.";
                            return false;
                        }
                        var min = $.trim($("#BIRTHDAYFROM").val());
                        if (dtReg.test(min) && !dateCompare(min, vl)) {
                            this.msg = "生日最大值应大于等于生日最小值.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "AVAPOINTFROM",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl != "") {
                        if (!/^\d+$/.test(vl)) {
                            this.msg = "可用积分最大值不正确应为数字.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "AVAPOINTTO",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl != "") {
                        if (!/^\d+$/.test(vl)) {
                            this.msg = "可用积分最大值不正确应为数字.";
                            return false;
                        }
                        var min = $.trim($("#AVAPOINTFROM").val());
                        if (/^\d+$/.test(min) && (min - 0) > (vl - 0)) {
                            this.msg = "可用积分最大值应大于等于可用积分最小值.";
                            return false;
                        }
                    }
                    return true;
                }
            });
            $.validateBind();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="pop_logging_body common_search">
            <table width="100%" class="common_table_noborde">
                <tr>
                    <td align="right">顾客卡号：
                    </td>
                    <td>
                        <input id="CARD_NO" type="text" class="common_search_input w150" />
                    </td>
                    <td align="right">姓名：
                    </td>
                    <td>
                        <input id="NAME" type="text" class="common_search_input w150" />
                    </td>
                </tr>
                <tr>
                    <td align="right">生日：</td>
                    <td>
                        <input type="text" id="BIRTHDAYFROM" onfocus="WdatePicker({startDate:'1980-1-1'})" class="common_search_input w70" />
                        至
                        <input type="text" id="BIRTHDAYTO" onfocus="WdatePicker({startDate:'1980-1-1'})" class="common_search_input w70" />
                    </td>
                    <td align="right">性别：
                    </td>
                    <td>
                        <select id="SEX" class="common_search_select w150">
                            <option value="">全部</option>
                            <option value="1">男</option>
                            <option value="0">女</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">年龄：
                    </td>
                    <td>
                        <input id="AGEFROM" type="text" class="common_search_input w70" />
                        到
                        <input id="AGETO" type="text" class="common_search_input w70" />
                    </td>
                    <td align="right">身份证：
                    </td>
                    <td>
                        <input id="ID_CARD" type="text" class="common_search_input w150" />
                    </td>
                </tr>
                <tr>
                    <td width="18%" align="right">职业：
                    </td>
                    <td>
                        <input id="TITLE" type="text" class="common_search_input w150" />
                    </td>
                    <td width="18%" align="right">家庭情况：
                    </td>
                    <td>
                        <input id="FAMILY" type="text" class="common_search_input w150" />
                    </td>
                </tr>
                <tr>
                    <td align="right">手机号码：
                    </td>
                    <td>
                        <input id="MOBILE" type="text" class="common_search_input w150" />
                    </td>
                    <td align="right">固定电话：
                    </td>
                    <td>
                        <input id="PHONE" type="text" class="common_search_input w150" />
                    </td>
                </tr>

                <tr>
                    <td align="right">所在省：
                    </td>
                    <td colspan="3">
                        <select id="province" class="common_search_select w70">
                            <option value="">请选择</option>
                            <%=Province%>
                        </select>市
                    <select id="city" disabled="disabled" class="common_search_select w70">
                        <option value="">请选择</option>
                    </select>
                        区
                    <select id="AREA_CODE" disabled="disabled" class="common_search_select w70">
                        <option value="">请选择</option>
                    </select>
                    </td>

                </tr>

                <tr>
                    <td align="right">推荐人卡号：
                    </td>
                    <td>
                        <input id="REFEREE_CARD" type="text" class="common_search_input w150" />
                    </td>
                    <td align="right">推荐人姓名：
                    </td>
                    <td>
                        <input id="REFEREE" type="text" class="common_search_input w150" />
                    </td>
                </tr>

                <tr>
                    <td align="right">注册日期：
                    </td>
                    <td>
                        <input id="DATE_CREATESTART" type="text" onfocus="WdatePicker()" class="common_search_input w70" />
                        到
                        <input id="DATE_CREATEEND" type="text" onfocus="WdatePicker()" class="common_search_input w70" />
                    </td>
                    <td align="right">可用积分：
                    </td>
                    <td>
                        <input id="AVAPOINTFROM" type="text" class="common_search_input w70" />
                        到
                        <input id="AVAPOINTTO" type="text" class="common_search_input w70" />
                    </td>
                </tr>
                <tr>
                    <td align="right">顾客级别：
                    </td>
                    <td id="LEVEL_CODE" colspan="3">
                        <%=CurstomerLevelOption %>
                    </td>
                </tr>
                <tr>
                    <td align="right">顾客分组：</td>
                    <td id="GROUP_KEY">
                        <%=CurstomerGroupOptions%>
                    </td>
                </tr>
            </table>
            <div class="pop_btn">
                <input type="button" id="btnSearch" class="common_btn_search" value="" />
            </div>
        </div>
    </form>
</body>
</html>
